package org.util;

import java.util.Calendar;

/**
 *
 * @author German Garcia
 */
public class DateFormatter {
    private static String year(Calendar time) {
        return Integer.toString(time.get(Calendar.YEAR));
        
    }

    private static String month(Calendar time) {
        return time.get(Calendar.MONTH) < 10 ? "0" + Integer.toString(time.get(Calendar.MONTH)) : Integer.toString(time.get(Calendar.MONTH));
    }

    private static String day(Calendar time) {
        return time.get(Calendar.DATE) < 10 ? "0" + Integer.toString(time.get(Calendar.DATE)) : Integer.toString(time.get(Calendar.DATE));
    }

    private static String hour(Calendar time) {
        return time.get(Calendar.HOUR_OF_DAY) < 10 ? "0" + Integer.toString(time.get(Calendar.HOUR_OF_DAY)) : Integer.toString(time.get(Calendar.HOUR_OF_DAY));
    }

    private static String minute(Calendar time) {
        return time.get(Calendar.MINUTE) < 10 ? "0" + Integer.toString(time.get(Calendar.MINUTE)) : Integer.toString(time.get(Calendar.MINUTE));
    }

    private static String second(Calendar time) {
        return time.get(Calendar.SECOND) < 10 ? "0" + Integer.toString(time.get(Calendar.SECOND)) : Integer.toString(time.get(Calendar.SECOND));
    }

    public static String format(Calendar time, boolean seconds) {
        if(seconds) {
            return year(time) + "-" + month(time) + "-" + day(time) + " " +
                   hour(time) + ":" + minute(time) + ":" + second(time);
        } else {
            return year(time) + "-" + month(time) + "-" + day(time) + " " +
                   hour(time) + ":" + minute(time) + ":00";
        }
    }
}
